﻿
@{
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

@using yiran.Areas.Admin.Models.Entity
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a>首页</a>
            <a class="p_name"></a>
            <a>
                <cite class="c_name"></cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="开始日期" name="start" id="start">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="截止日期" name="end" id="end">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="keywork" placeholder="角色名" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        @if ((ViewData["menu"] as List<sys_menu>).Where(c => c.action == "rolesdel").Any())
                        {
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                        }
                        @if ((ViewData["menu"] as List<sys_menu>).Where(c => c.action == "rolesadd").Any())
                        {

                            <button class="layui-btn" onclick="xadmin.open('添加角色','/admin/role/rolesadd')"><i class="layui-icon"></i>添加</button>
                        }
                    </div>
                    <div class="layui-card-body scroll">
                        <table class="layui-table layui-form">
                            <thead>
                                <tr>
                                    <th>
                                        <input type="checkbox" lay-filter="checkall" title="全选" lay- lay-skin="primary">
                                    </th>
                                    <th>角色名</th>
                                    <th>添加时间</th>
                                    <th>备注</th>
                                    <th>操作</th>
                            </thead>
                            <tbody>
                                @using yiran.Areas.Admin.Models.Request
                                @model PageRequestModel
                                @if (Model.total <= 0 || Model.data == null)
                                {
                                    <tr>
                                        <td colspan="7" align="center">暂无数据</td>
                                    </tr>
                                }
                                else
                                {
                                    var index = 0;
                                    @foreach (var m in Model.data)
                                    {
                                        <tr>
                                            <td>
                                                @if (@m.id != 1)
                                                {
                                                    <input type="checkbox" title="@(++index)" value="@m.id" name="id" lay-skin="primary">
                                                }
                                                else
                                                {
                                                    <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                                    @(++index)
                                                }
                                            </td>
                                            <td>@m.name</td>
                                            <td>@m.addtime.ToString("yyyy/MM/dd HH:mm:ss")</td>
                                            <td>@m.remark</td>
                                            <td class="td-manage">
                                                @if (m.id != 1)
                                                {
                                                    if ((ViewData["menu"] as List<sys_menu>).Where(c => c.action == "rolesedit").Any())
                                                    {
                                                        <a title="编辑" onclick="xadmin.open('编辑','/admin/role/rolesedit/@m.id')" href="javascript:;">
                                                            <i class="layui-icon">&#xe642;</i>
                                                        </a>
                                                    }
                                                    if ((ViewData["menu"] as List<sys_menu>).Where(c => c.action == "rolesdel").Any())
                                                    {
                                                        <a title="删除" onclick="member_del(this,'@m.id')" href="javascript:;">
                                                            <i class="layui-icon">&#xe640;</i>
                                                        </a>
                                                    }
                                                }
                                            </td>
                                        </tr>
                                    }
                                }
                                @Html.AntiForgeryToken()
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            <style>
                                .pagination {
                                    font-size: 0;
                                    margin-bottom: 25px;
                                }

                                    .pagination .click {
                                        cursor: pointer
                                    }

                                    .pagination a {
                                        text-decoration: none;
                                        border: 1px solid #009688;
                                        color: #009688;
                                        font-size: 13px;
                                        border-radius: 2px;
                                        margin: 0 4px;
                                    }

                                    .pagination span {
                                        color: #666;
                                        font-size: 13px;
                                        display: inline-block;
                                        border: 1px solid #ccc;
                                        padding: 0.2em 0.6em;
                                        margin: 0 4px;
                                    }

                                        .pagination span.pagetext {
                                            border: none
                                        }

                                    .pagination a:hover {
                                        background: #009688;
                                        color: #fff;
                                    }

                                    .pagination a {
                                        display: inline-block;
                                        padding: 0.2em 0.6em;
                                    }

                                    .pagination .page_current {
                                        background: #009688;
                                        color: #fff;
                                        border: 1px solid #009688;
                                        margin-right: 5px;
                                    }

                                .pagination {
                                    margin-top: 20px;
                                }

                                    .pagination .current.prev, .pagination .current.next {
                                        color: #999;
                                        border-color: #999;
                                        background: #fff;
                                    }
                            </style>
                            @Html.Raw(ViewData["page"])
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
            ,value:getUrlQuery("start") ? getUrlQuery("start")  : ""
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
            ,value:getUrlQuery("end") ? getUrlQuery("end")  : ""
        });
        $("input[name=keywork]").val(getUrlQuery("keywork") ? getUrlQuery("keywork") : "");
        // 监听全选
        form.on('checkbox(checkall)', function(data){
          if(data.elem.checked){
            $('tbody input[name = id]').prop('checked',true);
          }else{
            $('tbody input[name = id]').prop('checked',false);
          }
          form.render('checkbox');
        });

    });
    //删除
        @if ((ViewData["menu"] as List<sys_menu>).Where(c => c.action == "rolesdel").Any()) {
    <text>
      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？', function (index) {
              $.ajax({
                    url:'/Admin/Role/rolesdel',
                    type: 'POST',
                    data: {"id[]":id},
					dataType: 'json',
					async: true,
                    success: function (data, status, xhr) {
                        if (data.code == 200) {
                            layer.msg(data.result, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                location.reload();
                            });
                        } else {
                            layer.msg(data.result, { icon: 2 });
                        }
                    },
                    error: function () {
                        layer.msg("出错了~", { icon: 2 });
                    }
				});
          });
      }
      function delAll (argument) {
        var ids = [];

        // 获取选中的id
        $('tbody input[name = id]').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
        if (ids.length @Html.Raw("<") 1) {
            layer.msg("请选择要删除的行", { icon: 2, time: 2000 });
            return false;
        }
        layer.confirm('确认要删除吗？', function (index) {
           $.ajax({
                    url:'/Admin/Role/rolesdel',
                    type: 'POST',
                    data: {"id[]":ids},
					dataType: 'json',
					async: true,
                    success: function (data, status, xhr) {
                        if (data.code == 200) {
                            layer.msg(data.result, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                location.reload();
                            });
                        } else {
                            layer.msg(data.result, { icon: 2 });
                        }
                    },
                    error: function () {
                        layer.msg("出错了~", { icon: 2 });
                    }
				});
        });
    }
     </text>
        }
        // 获取url参数 getUrlQuery("id")
        function getUrlQuery(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            if(window.location.href.indexOf("?") < 0){
                return null;
            }
            let r = window.location.href.split("?")[1].match(reg);
            if (r != null) return decodeURIComponent(r[2]);
            return null;
        }

</script>
